package api

import (
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
	"online/api/handler"
	"online/api/middlewore"
	"online/consts"
)

func LoadRoutes(r *gin.Engine) {
	r.GET("/ping", handler.Ping)
	r.Use(middlewore.Cors())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)
			user.POST("/login", handler.Login)
		}
		online := api.Group("/online")
		{
			online.Use(gojwt.JWTAuth(consts.JWT_KEY))
			online.POST("/add", handler.AddOnline)
			online.POST("/update", handler.UpdateOnline)
			online.GET("/list", handler.ListOnline)
			online.GET("/page", handler.PageOnline)
			online.GET("/show", handler.ShowOnline)
		}
		collect := api.Group("/collect")
		{
			collect.Use(gojwt.JWTAuth(consts.JWT_KEY))
			collect.POST("/add", handler.AddCollect)
			collect.POST("/del", handler.DelCollect)
			collect.GET("/list", handler.ListCollect)
		}
		comment := api.Group("/comment")
		{
			comment.Use(gojwt.JWTAuth(consts.JWT_KEY))
			comment.POST("/add", handler.AddComment)
			comment.POST("/del", handler.DelComment)
			comment.GET("/list", handler.ListComment)
		}
	}
}
